<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-row>
          <el-col :span="5">
            <el-input
              placeholder="请输入内容"
              v-model="queryData.query"
              class="input-with-select"
              @clear="getOrderList"
              clearable
            >
              <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
            </el-input>
          </el-col>
        </el-row>
      </div>
      <template>
        <el-table :data="orderData" stripe style="width: 100%">
          <el-table-column type="index" label="序号"></el-table-column>
          <el-table-column prop="order_number" label="订单编号" width="900"></el-table-column>
          <el-table-column prop="order_price" label="订单价格"></el-table-column>
          <el-table-column prop="pay_status" label="是否付款">
            <template slot-scope="scope">
              <el-tag type="danger" v-if="scope.row.pay_status==='0'">未付款</el-tag>
              <el-tag type="success" v-else>已付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="is_send" label="是否发货"></el-table-column>
          <el-table-column prop="create_time" label="下单时间" width="200">
            <template slot-scope="scope">{{scope.row.create_time|dateFormat}}</template>
          </el-table-column>
          <el-table-column label="操作" width="180">
            <template slot-scope="scope">
              <el-tooltip
                class="item"
                effect="dark"
                content="修改地址"
                placement="top"
                :enterable="false"
              >
                <el-button
                  @click="getEditOrders(scope.row)"
                  type="primary"
                  icon="el-icon-edit"
                  size="mini"
                  round
                  class="r_btns"
                ></el-button>
              </el-tooltip>
              <el-tooltip
                class="item"
                effect="dark"
                content="物流进度"
                placement="top"
                :enterable="false"
              >
                <el-button
                  type="success"
                  icon="el-icon-location-outline"
                  size="mini"
                  @click="showProgress(scope.row)"
                  round
                  class="r_btns"
                ></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <!-- 分页 -->
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pagenum"
        :page-sizes="[2, 5, 10, 15]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 修改地址 -->
    <el-dialog
      title="修改地址"
      :visible.sync="editAddressDialogVisible"
      width="50%"
      @close="dialogClose('editAddressRef')"
    >
      <el-form
        :model="editAddressForm"
        :rules="editAddressRules"
        ref="editAddressRef"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="editAddressForm.address1"
            :options="citydata"
            :props="{ expandTrigger: 'hover' }"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="editAddressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editAddressDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editAddressDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流进度 -->
    <el-dialog title="物流进度" :visible.sync="progressDialogVisible" width="50%">
      <el-timeline :reverse="true">
        <el-timeline-item
          v-for="(activity, index) in progressList"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import citydata from "./citydata.js";
export default {
  data() {
    return {
      pagenum: 1,
      pagesize: 10,
      total: 10,
      queryData: {
        query: ""
      },
      orderData: [],
      //   编辑地址
      editAddressDialogVisible: false,
      editAddressForm: {
        address1: "",
        address2: ""
      },
      editAddressRules: {
        address1: [
          { required: true, message: "请输入省市区/县", trigger: "blur" }
        ],
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" }
        ]
      },
      citydata,
      //   物流进度
      progressDialogVisible: false,
      progressList: []
    };
  },

  created() {
    this.getOrders();
  },

  methods: {
    async getOrders() {
      const { data: res } = await this.$http.get("orders", {
        params: { pagenum: this.pagenum, pagesize: this.pagesize }
      });
      if (res.meta.status !== 200) return this.$message.error("获取错误");
      this.orderData = res.data.goods;
    },
    getOrderList() {},
    // 分页
    handleSizeChange(val) {
      this.pagesize = val;
      this.getOrders();
    },
    handleCurrentChange(val) {
      this.pagenum = val;
      this.getOrders();
    },
    // 修改地址
    getEditOrders() {
      this.editAddressDialogVisible = true;
    },
    dialogClose(ref) {
      this.$refs[ref].resetFields();
    },
    // 物流进度
    async showProgress() {
      this.progressDialogVisible = true;
      const { data: res } = await this.$http.get("/kuaidi/1106975712662");
      console.log(res);
      if (res.meta.status !== 200)
        return this.$message.error("获取快递信息失败");
      this.progressList = res.data;
    }
  }
};
</script>

<style scoped lang='less'>
.el-cascader {
  width: 100%;
}
</style>
